<?php
namespace Common\Lib;

class wechat {
	
	public $appid = 'wx4f3e1b96619b7d49';	// wx77a2f06d44d66954

	public $appsecret = '10c14cef9a1d99821eca9633e11306f5';	// ce00abbf43a6930ad37115181d9a8bf8

	public function wxauth(){
		vendor('wechat.Weauth','simplewind/Core/Library/Vendor/','.php');
		// vendor('Wechat','simplewind/Core/Library/Vendor/','.php');

		$options = array(
            'token'=>'tokenaccesskey', //填写你设定的key
            'appid'=> $this->appid, //填写高级调用功能的app id, 请在微信开发模式后台查询
            'appsecret'=> $this->appsecret, //填写高级调用功能的密钥
        );
        $auth = new \Weauth($options);
        return $auth->wxuser;
	}

	/**
	 * /
	 * @param  [type] $open_id     [description]
	 * @param  [type] $template_id [description]
	 * @param  [type] $data        
	 *         array(
	 *				"参数名1"=> array(
	 *					"value"=>"参数",
	 *					"color"=>"#173177"	 //参数颜色
	 *				),
	 *				"Date"=>array(
	 *					"value"=>"06月07日 19时24分",
	 *					"color"=>"#173177"
	 *				),
	 *				"CardNumber"=>array(
	 *					"value"=>"0426",
	 *					"color"=>"#173177"
	 *				),
	 *				"Type"=>array(
	 *					"value"=>"消费",
	 *					"color"=>"#173177"
	 *				)
	 *			)
	 * @return [type]              [description]
	 */
	public function sendTemplateMessage($open_id,$template_id,$data){
		vendor('wechat.Wechat','simplewind/Core/Library/Vendor/','.php');
		$options = array(
            'token'=>'tokenaccesskey', //填写你设定的key
            'appid'=> $this->appid, //填写高级调用功能的app id, 请在微信开发模式后台查询
            'appsecret'=> $this->appsecret, //填写高级调用功能的密钥
        );
        $wechat = new \Wechat($options);
        $send_data = array(
			"touser"=>$open_id,
			"template_id"=>$template_id,
			"url"=>"",
			"topcolor"=>"#FF0000",
			"data"=>$data,
        );

        $result = $wechat->sendTemplateMessage($send_data);
        $result['send_data'] = $send_data;
        // dump($wechat->errCode);
        // dump($wechat->errMsg);
		return $result;
	}
}
?>